package com.wsjj.yjh.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;


@Service
@Slf4j
public class OrderService {

    @Resource
    private RedisTemplate redisTemplate;

    public static final String ORDER_KEY = "ord:";

    public void addOrder(){
        int keyId = ThreadLocalRandom.current().nextInt(1000) + 1;
        System.out.println(keyId);
        String serialNo = UUID.randomUUID().toString();

        String key = ORDER_KEY+keyId;
        String value = "京东订单" + serialNo;

        redisTemplate.opsForValue().set(key,value);

    }

    public String getOrder(String key){
        String keys = ORDER_KEY+key;
        System.out.println("查询出来的结果  "+(String) redisTemplate.opsForValue().get(keys));
        return (String) redisTemplate.opsForValue().get(keys);
    }

}
